package com.ruoyi.module.memberOrganizational.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.memberOrganizational.domain.MemberOrganizational;
import com.ruoyi.module.memberOrganizational.service.IMemberOrganizationalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织架构Controller
 * 
 * @author yqq
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/api/memberOrganizational")
public class MemberOrganizationalController extends BaseController
{
    @Autowired
    private IMemberOrganizationalService memberOrganizationalService;

    /**
     * 查询组织架构列表
     */
    @PreAuthorize("@ss.hasPermi('api:memberOrganizational:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberOrganizational memberOrganizational)
    {
        startPage();
        List<MemberOrganizational> list = memberOrganizationalService.selectMemberOrganizationalList(memberOrganizational);
        return getDataTable(list);
    }

    /**
     * 导出组织架构列表
     */
    @PreAuthorize("@ss.hasPermi('api:memberOrganizational:export')")
    @Log(title = "组织架构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberOrganizational memberOrganizational)
    {
        List<MemberOrganizational> list = memberOrganizationalService.selectMemberOrganizationalList(memberOrganizational);
        ExcelUtil<MemberOrganizational> util = new ExcelUtil<MemberOrganizational>(MemberOrganizational.class);
        util.exportExcel(response, list, "组织架构数据");
    }

    /**
     * 获取组织架构详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:memberOrganizational:query')")
    @GetMapping(value = "/{organizationalId}")
    public AjaxResult getInfo(@PathVariable("organizationalId") Long organizationalId)
    {
        return success(memberOrganizationalService.selectMemberOrganizationalByOrganizationalId(organizationalId));
    }

    /**
     * 新增组织架构
     */
    @PreAuthorize("@ss.hasPermi('api:memberOrganizational:add')")
    @Log(title = "组织架构", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MemberOrganizational memberOrganizational)
    {
        return toAjax(memberOrganizationalService.insertMemberOrganizational(memberOrganizational));
    }

    /**
     * 修改组织架构
     */
    @PreAuthorize("@ss.hasPermi('api:memberOrganizational:edit')")
    @Log(title = "组织架构", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody MemberOrganizational memberOrganizational)
    {
        return toAjax(memberOrganizationalService.updateMemberOrganizational(memberOrganizational));
    }

    /**
     * 删除组织架构
     */
    @PreAuthorize("@ss.hasPermi('api:memberOrganizational:remove')")
    @Log(title = "组织架构", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{organizationalId}")
    public AjaxResult remove(@PathVariable("organizationalId") Long organizationalId)
    {
        return toAjax(memberOrganizationalService.deleteMemberOrganizationalByOrganizationalId(organizationalId));
    }
}
